<template>
	<view>
		<view class="interact-tools" style="margin-bottom: 15px">
			<div class="paddingBox">
				<view class="myorder">
					<view class="wode">合作</view>
				</view>
				<view class="interact-container">
					<view class="interact-item"
						v-if="login===false||(login===true&&[1, 2, 4].indexOf(this.userInfo.partnerType) ==-1)"
						@click="toBusinessSettled">
						<image src="/static/myimg/dianpu.png" mode="widthFix"></image>
						<view class="text">商家入驻</view>
					</view>
					<view class="interact-item" v-if="login === true && haveStore == true" @click="toBusinessSettled">
						<image src="/static/myimg/dianpu.png" mode="widthFix"></image>
						<view class="text">店铺管理</view>
					</view>
					<view v-if="login===true&& [1, 2, 4].indexOf(this.userInfo.partnerType) >-1" class="interact-item"
						@click="toPartner()">
						<image src="/static/myimg/hehuoren.png" mode="widthFix"
							style="width: 80rpx; height: 80rpx;display: block;"></image>
						<view class="text">{{name}}</view>
					</view>
					<view class="interact-item" v-else @click="gotoPartnerList">
						<image src="/static/myimg/hehuoren.png" mode="widthFix"></image>
						<view class="text">成为合伙人</view>
					</view>
					<view class="interact-item" v-if="userInfo.partnerType==1 || userInfo.partnerType==2"
						@click="navigateTo('/pages/tabbar/user/post/post')">
						<image src="/static/myimg/tuiguang.png" mode="widthFix"></image>
						<view class="text">推广码</view>
					</view>
					<view class="interact-item" @click="navigateTo('/pages/mine/set/policy')">
						<image src="/static/myimg/jiameng.png" mode="widthFix"></image>
						<view class="text">加盟政策</view>
					</view>
				</view>
			</div>
			<div class="paddingBox" style="margin-top: 30rpx;">
				<view class="myorder">
					<view class="wode">服务</view>
				</view>
				<view class="interact-container">
					<view class="interact-itemsss" @click="navigateTo('/pages/mine/myCollect')">
						<image src="/static/myimg/shoucang.png" mode="widthFix"></image>
						<view class="text">我的收藏</view>
					</view>
					<view class="interact-itemsss" @click="navigateTo('/pages/mine/myTracks')" v-if="login===true">
						<image src="/static/myimg/zuji.png" mode=""></image>
						<view>我的足迹</view>
					</view>
					<view class="interact-itemsss" @click="navigateTo('/pages/order/evaluate/myEvaluate')">
						<image src="/static/myimg/pingjia.png" mode="widthFix"></image>
						<view class="text">我的评价</view>
					</view>
					<view class="interact-itemsss" @click="navigateTo('/pages/order/complain/complainList')">
						<image src="/static/myimg/yijian.png" mode="widthFix"></image>
						<view class="text">我的投诉</view>
					</view>
					<view class="interact-itemsss" @click="navigateTo('/pages/mine/set/feedBack')">
						<image src="/static/myimg/tousu.png" mode="widthFix"></image>
						<view class="text">意见反馈</view>
					</view>
					<button style="margin: 0;border: none;background-color: transparent;" class="interact-itemsss"
						open-type="contact" bindcontact="handleContact" session-from="sessionFrom">
						<image src="/static/myimg/kefu.png" mode="widthFix"></image>
						<view class="text">联系客服</view>
					</button>
					<view class="interact-itemsss" @click="navigateTo('/pages/mine/address/addressManage')">
						<image src="/static/myimg/dizhi.png" mode="widthFix"></image>
						<view class="text">地址管理</view>
					</view>
					<view class="interact-itemsss" @click="navigateTo('/pages/mine/invoiceManage/invoiceManage')">
						<image src="/static/myimg/fapiao.png" mode="widthFix"></image>
						<view class="text">发票信息</view>
					</view>
					<view class="interact-itemsss" @click="navigateTo('/pages/mine/help/helpList?type=help')">
						<image src="/static/myimg/bangzhu.png" mode="widthFix"></image>
						<view class="text">帮助中心</view>
					</view>
					<view class="interact-itemsss" @click="navigateTo('/pages/mine/set/setUp')">
						<image src="/static/myimg/shezhi.png" mode="widthFix"></image>
						<view class="text">设置管理</view>
					</view>
				</view>
			</div>
		</view>
	</view>
</template>

<script>
	import {
		userInfo
	} from "@/api/goods";
	import {
		GetStoreStatus,
		BecomeTuiguangyuan,
		ShopMoney,
		CreatePartner,
		GetStoreFeeStatus,
		getUserInfo
	} from "@/api/members.js"
	import * as API_Trade from "@/api/trade";
	import config from "@/config/config.js"
	import storage from "@/utils/storage.js";
	export default {
		data() {
			return {
				login: false,
				userInfo: '',
				businessState: '',
				name: '',
				haveStore: false
			}
		},
		mounted() {
			this.login = this.$options.filters.isLogin("auth")
			this.userInfo = storage.getUserInfo();
			this.haveStore = storage.getUserInfo().haveStore
			this.businessState = storage.getBusiness();
		},
		computed: {},
		methods: {
			handleContact(e) {
				console.log(e.detail.path)
				console.log(e.detail.query)
			},
			init() {
				this.login = this.$options.filters.isLogin("auth")
				this.businessState = storage.getBusiness()
				this.userInfo = storage.getUserInfo();
				this.haveStore = storage.getUserInfo().haveStore
				let name = ''
				if (this.userInfo.partnerType == 4) {
					name = '城市合伙人'
				} else if (this.userInfo.partnerType == 1) {
					name = '事业合伙人'
				} else if (this.userInfo.partnerType === 2) {
					name = '天使合伙人'
				} else {
					name = '推广员'
				}
				this.name = name
				this.paymentType = "WECHAT_MP2";
				this.paymentClient = "MP";
			},
			// 成为推广员
			handleTuiguangyuan() {
				let loginState = storage.getHasLogin();
				if (!loginState) {
					this.$options.filters.forceLogin()
					return
				}
				uni.navigateTo({
					url: "/pages/partner/partnerGuide"
				})
			},
			navigateTo(url) {
				uni.navigateTo({
					url,
				});
			},
			// 商家入驻  店铺管理
			toBusinessSettled() {
				// 1.是否登录
				let loginState = storage.getHasLogin();
				if (!loginState) {
					this.$options.filters.forceLogin()
				} else {
					// 2.当前店铺状态
					this.businessStateOperate()
				}
			},
			businessStateOperate() {
				let that = this
				if (this.businessState.storeByMember == 'OPEN') {
					let storeId = this.userInfo.storeId
					uni.navigateTo({
						url: "/pages/product/shopPage?id=" + storeId
					})
				} else if (this.businessState.storeByMember == 'CLOSED') {
					uni.showToast({
						title: "店铺关闭！",
						duration: 2000,
						icon: "none",
					});
				} else if (this.businessState.storeByMember == 'REFUSED') {
					uni.showModal({
						showCancel: true,
						confirmText: '重新提审',
						title: '店铺申请拒绝',
						content: '拒绝原因：' + this.businessState.causer,
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: "/pages/business/businessSettled/businessSettled?type=edit"
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				} else if (this.businessState.storeByMember == 'APPLYING' || this.businessState.storeByMember ==
					'FIRSTTRIAL') {
					uni.showToast({
						title: "店铺申请正在审核中",
						duration: 2000,
						icon: "none",
					});
				} else if (this.businessState.storeByMember == 'LOGOUT') {
					uni.showToast({
						title: "店铺已注销",
						duration: 2000,
						icon: "none",
					});

				} else {
					uni.navigateTo({
						url: "/pages/business/guide/guide"
					})
				}
			},
			// 跳转天使合伙人  事业合伙人页面
			toPartner() {
				let loginState = storage.getHasLogin();
				if (!loginState) {
					this.$options.filters.forceLogin()
					return
				}
				this.navigateTo("/pages/partner/partnerList/partnerList?name=" + this.name)
			},
			async gotoPartnerList() {
				let res = await userInfo()
				let data = res.data.result
				let partnerType = ''
				if (data.partnerType == 1) {
					partnerType = '事业合伙人'
				} else if (data.partnerType == 2) {
					partnerType = '天使合伙人'
				} else if (data.partnerType == 4) {
					partnerType = '城市合伙人'
				}
				if (data.auditState === null || data.auditState === 'WAIT_SUBMIT') {
					uni.navigateTo({
						url: '/pages/partner/partner',
					})

				} else {
					// 申请状态
					uni.navigateTo({
						url: '/pages/partner/applySate?auditState=' + data.auditState
					})
				}
			}
		},
	};
</script>

<style lang="scss" scoped>
	.interact-tools {
		border-left: none;
		border-right: none;

		.interactBox {
			height: 156rpx;
		}

		.interact-container {
			.interact-item-img {
				width: 52rpx !important;
				height: 52rpx !important;
				margin: 0 auto 6rpx auto !important;
			}

			image {
				width: 80rpx;
				height: 80rpx;
			}

			display: flex;
			align-items: center;
			flex-wrap: wrap;
			text-align: center;

			.interact-item {
				font-size: $font-sm;
				width: 25%;
				padding: 30rpx 0;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				&::after {
					content: '';
					border: none;
				}

				.text {
					height: 28upx;
					line-height: 28upx;
				}
			}

			.interact-itemsss {
				font-size: $font-sm;
				width: 20%;
				padding: 30rpx 0;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				&::after {
					content: '';
					border: none;
				}

				.text {
					height: 28upx;
					line-height: 28upx;
				}
			}
		}
	}

	.paddingBox {
		margin: 0 20rpx;
		background: #fff;
		border-radius: 20rpx;
		box-shadow: 0 4rpx 24rpx 0 rgba($color: #f6f6f6, $alpha: 1);

		.myorder {
			display: flex;
			flex: 1;
			align-items: center;
			justify-content: space-between;
			padding: 26rpx 3%;

			.wode {
				font-size: 30rpx;
				color: rgba(36, 36, 36, 1);
				font-weight: bold;
			}
		}
	}
</style>
